Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime: Refactor conn cache to contain and detect hanging opens/closes #3666

Merged

Conversation

begelundmuller
Copy link
Contributor

@begelundmuller begelundmuller commented Dec 8, 2023

These refactors enable:

  • Connection opens and closes to always run outside of the connection cache's mutex, preventing hanging connections from blocking the connection cache entirely.
  • Periodic monitoring and logging of hanging connection opens/closes

Contributes to https://github.com/rilldata/rill-private-issues/issues/17

@begelundmuller begelundmuller self-assigned this Dec 8, 2023
@begelundmuller begelundmuller marked this pull request as ready for review December 14, 2023 15:15
closed bool
mu sync.Mutex
entries map[string]*entry
lru *simplelru.LRU
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also expose metrics around lru and entries size and optionally connection open and close times.

// Options configures a new connection cache.
type Options struct {
// MaxConnectionsIdle is the maximum number of non-acquired connections that will be kept open.
MaxConnectionsIdle int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Usually the name is MaxIdleConnections (https://pkg.go.dev/database/sql#DB.SetMaxIdleConns)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@begelundmuller begelundmuller merged commit fa2e166 into main Dec 15, 2023
4 checks passed
@begelundmuller begelundmuller deleted the begelundmuller/refactor-conn-cache-open-close-background branch December 15, 2023 11:29
mindspank pushed a commit that referenced this pull request Dec 18, 2023
…es (#3666)

* Runtime: Refactor conn cache to contain and detect hanging opens/closes

* Extract connection cache to pkg + use a singleflight

* Add tests

* Make tests pass

* increase test sleeps for clsoe

* Fix various race conditions

* Integrate singleflight with conncache's mutex

* Increase timeouts

* Better comments

* Prevent deadlock when closing while opening

* Address review comments

* Remove redundant var
esevastyanov pushed a commit that referenced this pull request Dec 19, 2023
…es (#3666)

* Runtime: Refactor conn cache to contain and detect hanging opens/closes

* Extract connection cache to pkg + use a singleflight

* Add tests

* Make tests pass

* increase test sleeps for clsoe

* Fix various race conditions

* Integrate singleflight with conncache's mutex

* Increase timeouts

* Better comments

* Prevent deadlock when closing while opening

* Address review comments

* Remove redundant var

(cherry picked from commit fa2e166)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants